﻿@using CML.Intercamber.Business
@model Users
@{
    ViewBag.PageTitle = Resources.Intercamber.Moderate_PageName;
}
@section PageHead
{

}
@section PageContent
{
    @{
        Users user = ViewBag.User;   
    }
    <script type="text/javascript">
        var level = "@ViewBag.Level";
        var node = "@ViewBag.Node";
        var userTarget = @user.IdUser;

        var moderationManager = new function() {
            this.add = function() {
                var msg = $("#moderationMessage").val();
                if (msg.length < 25) {
                    alert("@Html.Raw(Resources.Intercamber.Moderate_PleaseDescribe)");
                    return;
                }
                
                var jsonParams = JSON.stringify({
                    IdUserTarget: userTarget, 
                    Message: msg, 
                    Context: level + ";"  +node, 
                });
                $("#loading").show();
                $("#btnSave").hide();
                $.ajax({
                    type: "POST",
                    url: "/Account/AddModeration",
                    contentType: "application/json; charset=utf-8",
                    data: jsonParams,
                    dataType: "json",
                    success: function (result) {
                        if (result == true) {
                            $("#buttons").hide();
                            $("#messageSaved").show();
                        } 
                    },
                    error: function (result) {
                        $("#loading").hide();
                        $("#btnSave").show();
                        alert("Service error!");
                        debugger;
                    }
                });
            };
        };

        $(function() {
            $(".jqbutton").button();
            $("#moderationMessage").focus();
        });
    </script>
    @string.Format(Resources.Intercamber.Moderate_AskMessage, user.UserNameComplete)
    <textarea id="moderationMessage" placeholder="..." aria-label="..." style="width: 100%; border: 0.3px dotted lightgray; padding: 2px; margin: 10px 0 10px 0;" rows="4"></textarea>
    <div id="buttons">
        <button id="btnSave" class="jqbutton" onclick="moderationManager.add(); return false; ">@Resources.Intercamber.Moderation_ModerateMessage</button>
        <span id="loading" style="display: none;">
            <img src="~/Images/Loading.gif" />
            @Resources.Intercamber.Loading
        </span>
    </div>
    <div id="messageSaved" style="display:none">
        <img src="~/Images/Check.png" style="margin:10px; float:left;" />@Resources.Intercamber.Moderate_Saved
    </div>
}